
package py.una.pol.raphapy.autoventas.model;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Rafael E. Benegas
 */
@Entity
@Table(name = "documento_persona")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "DocumentoPersona.findAll", query = "SELECT d FROM DocumentoPersona d"),
    @NamedQuery(name = "DocumentoPersona.findByCodTipDoc", query = "SELECT d FROM DocumentoPersona d WHERE d.documentoPersonaPK.codTipDoc = :codTipDoc"),
    @NamedQuery(name = "DocumentoPersona.findByCodPer", query = "SELECT d FROM DocumentoPersona d WHERE d.documentoPersonaPK.codPer = :codPer"),
    @NamedQuery(name = "DocumentoPersona.findByNumDoc", query = "SELECT d FROM DocumentoPersona d WHERE d.numDoc = :numDoc")})
public class DocumentoPersona implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected DocumentoPersonaPK documentoPersonaPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "num_doc")
    private String numDoc;
    @JoinColumn(name = "cod_tip_doc", referencedColumnName = "cod_tip_doc", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private TipoDocumento tipoDocumento;
    @JoinColumn(name = "cod_per", referencedColumnName = "cod_per", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Persona persona;

    public DocumentoPersona() {
    }

    public DocumentoPersona(DocumentoPersonaPK documentoPersonaPK) {
        this.documentoPersonaPK = documentoPersonaPK;
    }

    public DocumentoPersona(DocumentoPersonaPK documentoPersonaPK, String numDoc) {
        this.documentoPersonaPK = documentoPersonaPK;
        this.numDoc = numDoc;
    }

    public DocumentoPersona(String codTipDoc, long codPer) {
        this.documentoPersonaPK = new DocumentoPersonaPK(codTipDoc, codPer);
    }

    public DocumentoPersonaPK getDocumentoPersonaPK() {
        return documentoPersonaPK;
    }

    public void setDocumentoPersonaPK(DocumentoPersonaPK documentoPersonaPK) {
        this.documentoPersonaPK = documentoPersonaPK;
    }

    public String getNumDoc() {
        return numDoc;
    }

    public void setNumDoc(String numDoc) {
        this.numDoc = numDoc;
    }

    public TipoDocumento getTipoDocumento() {
        return tipoDocumento;
    }

    public void setTipoDocumento(TipoDocumento tipoDocumento) {
        this.tipoDocumento = tipoDocumento;
    }

    public Persona getPersona() {
        return persona;
    }

    public void setPersona(Persona persona) {
        this.persona = persona;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (documentoPersonaPK != null ? documentoPersonaPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        
        if (!(object instanceof DocumentoPersona)) {
            return false;
        }
        DocumentoPersona other = (DocumentoPersona) object;
        if ((this.documentoPersonaPK == null && other.documentoPersonaPK != null) || (this.documentoPersonaPK != null && !this.documentoPersonaPK.equals(other.documentoPersonaPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "py.una.pol.raphapy.autoventas.model.DocumentoPersona[ documentoPersonaPK=" + documentoPersonaPK + " ]";
    }
    
}
